<?php

namespace app\common\service;

class Qwq
{
    public function index($content)
    {
  
        $url = 'https://api.siliconflow.cn/v1/chat/completions';
        $apiKey = 'sk-tiuvcznrtvpmjnipckrwiaotbspbpeslgbxadpwznrfdqocc';
        
        $data = [
            'model' => 'Qwen/QwQ-32B',
            'messages' => [
                [
                    'role' => 'user',
                    'content' => $content
                ]
            ],
            'stream' => false,
            'max_tokens' => 4096,
            'thinking_budget' => 4096,
            'min_p' => 0.05,
            'stop' => null,
            'temperature' => 0.3,
            'top_p' => 0.9,
            'top_k' => 50,
            'frequency_penalty' => 0.5,
            'n' => 1,
            'response_format' => [
                'type' => 'text'
            ]
        ];

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Authorization: Bearer ' . $apiKey,
            'Content-Type: application/json'
        ]);

        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        
        if (curl_errno($ch)) {
            return ['error' => curl_error($ch)];
        }
        
        curl_close($ch);
        
        $data = json_decode($response, true);
   
        return $data;
    }
}